<?php
	
	if( !$this->network->id ) {
		$this->redirect('home');
	}
	if( !$this->user->is_logged ) {
		$this->redirect('signin');
	}
	
	$this->load_langfile('inside/global.php');
	$this->load_langfile('inside/settings.php');
	
	$D->page_title	= $this->lang('settings_sms_pagetitle', array('#SITE_TITLE#'=>$C->SITE_TITLE));
	
	
	
	$D->submit	= FALSE;
	$D->error	= FALSE;
	$D->errmsg1	= '';
	$D->errmsg2	= '';



	
		$r = $db2->query('SELECT tel FROM users WHERE id="'. $this->user->id.'" limit 1');

		while($obj = $db2->fetch_object($r)) {
			
			$D->i->tel=$obj->tel;
		
			}
	

	if( isset($_POST['sbm']) ) {
		$D->submit	= TRUE;

		$D->i->tel	= trim($_POST['tel']);
if( strlen($D->i->tel)!=11 AND strlen($D->i->tel)!=0) {
$D->error	= TRUE;
			$D->errmsg1	= 'st_sms_error1';
		}		

$t=$db2->query('select id from users where tel="'.$D->i->tel.'"');
if($obj =$db2->fetch_object($t)  AND strlen($D->i->tel)!=0) {

$D->error	= TRUE;
			$D->errmsg2	= 'st_sms_error2';
		}	

if (!$D->error){

		$db2->query('UPDATE users SET tel="'.$D->i->tel.'" WHERE id="'. $this->user->id.'"');
	$systemid=$C->SMSID;
	$web=$C->SITE_URL.qqphp;
	$tel=$D->i->tel;
		$acContent = "
				<XML>
				<System>
				<SystemID>$systemid</SystemID>
				<command>smsbind</command>
				</System>
				<User>
				<url>$web</url>
				<tel>$tel</tel> 
				</User>
				</XML>";
$url="http://qq.51wb.net/bind.php";
				$header[]="Content-Type: text/xml; charset=utf-8";
				$ch = curl_init($url);
				curl_setopt($ch, CURLOPT_URL, $url);
				curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
				curl_setopt($ch, CURLOPT_POST, 1); 
				curl_setopt($ch, CURLOPT_POSTFIELDS, $acContent);
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
				curl_setopt($ch, CURLOPT_HEADER, 0);
				$res = curl_exec($ch);
				//echo $res;
				curl_close($ch);
		
		
		$this->user->sess['LOGGED_USER']	= $this->network->get_user_by_id($this->user->id, TRUE);
		$this->user->info	= & $this->user->sess['LOGGED_USER'];
		
		$u	= $this->user->info;
		

			$n	= intval( $this->network->get_user_notif_rules($this->user->id)->ntf_them_if_i_edt_profl );
			if( $n == 1 ) {
				$this->load_langfile('inside/notifications.php');
			
				$followers	= array_keys($this->network->get_user_follows($this->user->id)->followers);
				foreach($followers as $uid) {
					$send_post	= FALSE;
					$send_mail	= FALSE;
					$n	= intval( $this->network->get_user_notif_rules($uid)->ntf_me_if_u_edt_profl );
					if( $n == 2 ) { $send_post = TRUE; } elseif( $n == 3 ) { $send_mail = TRUE; } elseif( $n == 1 ) { $send_post = TRUE; $send_mail = TRUE; }
					if( $send_post ) {
						$lng	= array('#USER#'=>'<a href="'.$C->SITE_URL.$this->user->info->username.'" title="'.htmlspecialchars($this->user->info->fullname).'"><span class="mpost_mentioned">@</span>'.$this->user->info->username.'</a>');
						$this->network->send_notification_post($uid, 0, 'msg_ntf_me_if_u_sms', $lng, 'replace');
					}
					
				}
			}
		}
	}
	
	$this->load_template('settings_sms.php');
	
?>